<template>
	<div class="components-container">
        <!-- 新增/修改 -->
        <sweet-modal ref="dialog" class="dialog">
          <h3>{{title}}</h3>
            <div style="height:200px; margin:30px 50px">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">逝者姓名</label>
                        <div class="layui-input-inline">
                            <el-input v-model="ashesData.TMMREGNAME"></el-input>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">逝者性别</label>
                        <div class="layui-input-inline">
                            <el-select v-model="ashesData.TMMREGSEX" filterable>
                                <el-option v-for="item in xblx" :key="item.CODNAME" :label="item.CODALIAS" :value="item.CODNAME">
                                </el-option>
                            </el-select>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">逝者年龄</label>
                        <div class="layui-input-inline">
                            <el-input-number v-model="ashesData.TMMREGAGE" :min="0"></el-input-number>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">墓穴位置</label>
                        <div class="layui-input-inline">
                            <el-input v-model="ashesData.TMMPOSTION"></el-input>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                     <div class="layui-inline">
                        <label class="layui-form-label">家属姓名</label>
                        <div class="layui-input-inline">
                            <el-input v-model="ashesData.TMMHANDLERNAME"></el-input>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">联系电话</label>
                        <div class="layui-input-inline">
                            <el-input v-model="ashesData.TMMHANGDLERLINK"></el-input>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <!-- <div class="layui-inline">
                        <label class="layui-form-label">墓穴编号</label>
                        <div class="layui-input-inline">
                            <el-input v-model="ashesData.ASSXP"></el-input>
                        </div>
                    </div> -->
                    <div class="layui-inline">
                        <label class="layui-form-label">死亡日期</label>
                        <div class="layui-input-inline">
                            <el-date-picker v-date type="date" placeholder="选择死亡日期" v-model="ashesData.TMMDEATHDATE" format="yyyy-MM-dd"></el-date-picker>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">下葬日期</label>
                        <div class="layui-input-inline">
                            <el-date-picker v-date type="date" placeholder="选择下葬日期" v-model="ashesData.TMMBURIALDATE"></el-date-picker>
                        </div>
                    </div>
                </div>
                 <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">迁出日期</label>
                        <div class="layui-input-inline">
                            <el-date-picker v-date type="date" placeholder="选择迁出日期" v-model="ashesData.TMMMOVEOUTDATE"></el-date-picker>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">购墓日期</label>
                        <div class="layui-input-inline">
                            <el-date-picker v-date type="date" placeholder="选择迁出日期" v-model="ashesData.TMMPURCHASEDATE"></el-date-picker>
                        </div>
                    </div>
                </div>
                 <!-- <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">所在列</label>
                        <div class="layui-input-inline">
                            <el-input v-model="ashesData.ASSXP"></el-input>
                        </div>
                    </div>
                </div> -->
            </div>
            <div class="layui-form-item btnCenter">
                <el-button @click="closeDialog">取消</el-button>
                <el-button type="primary" @click="submit">确定</el-button>
            </div>
        </sweet-modal>
        <!-- 详情 -->
        <sweet-modal ref="dialogInfo" class="dialog">
          <h3>{{title}}</h3>
            <div style=" height:200px; margin:30px 50px">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">逝者姓名</label>
                        <div class="layui-input-inline">
                            <el-input v-model="ashesData.TMMREGNAME" readonly></el-input>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">逝者性别</label>
                        <div class="layui-input-inline">
                             <el-input v-model="ashesData.TMMREGSEXDESC" readonly></el-input>
                        </div>
                    </div>
                </div>
                 <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">逝者年龄</label>
                        <div class="layui-input-inline">
                            <el-input v-model="ashesData.TMMREGAGE" readonly></el-input>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">墓穴位置</label>
                        <div class="layui-input-inline">
                            <el-input v-model="ashesData.TMMPOSTION" readonly></el-input>
                        </div>
                    </div>
                </div>
                 <div class="layui-form-item">
                     <div class="layui-inline">
                        <label class="layui-form-label">联系电话</label>
                        <div class="layui-input-inline">
                            <el-input v-model="ashesData.TMMHANGDLERLINK" readonly></el-input>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">家属姓名</label>
                        <div class="layui-input-inline">
                            <el-input v-model="ashesData.TMMHANDLERNAME" readonly></el-input>
                        </div>
                    </div>
                </div>
                  <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">死亡日期</label>
                        <div class="layui-input-inline">
                            <el-date-picker v-date type="date" placeholder="选择死亡日期" v-model="ashesData.TMMDEATHDATE" format="yyyy-MM-dd" readonly></el-date-picker>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">下葬日期</label>
                        <div class="layui-input-inline">
                            <el-date-picker v-date type="date" placeholder="选择下葬日期" v-model="ashesData.TMMBURIALDATE" readonly></el-date-picker>
                        </div>
                    </div>
                </div>
                 <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">迁出日期</label>
                        <div class="layui-input-inline">
                            <el-date-picker v-date type="date" placeholder="选择迁出日期" v-model="ashesData.TMMMOVEOUTDATE" readonly></el-date-picker>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">购墓日期</label>
                        <div class="layui-input-inline">
                            <el-date-picker v-date type="date" placeholder="选择迁出日期" v-model="ashesData.TMMPURCHASEDATE" readonly></el-date-picker>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item btnCenter">
                <el-button @click="closeDialog">取消</el-button>
            </div>
        </sweet-modal>
	</div>

</template>
<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/common.scss";
.el-button + .el-button {
  margin-left: 0;
}
</style>
<script>
import sweetModal from "@/components/sweetModal";
import dataTable from "@/components/Table/DataTable";
import apiBase from "@/api/apiBase.js";
import { formatDate, timeStringToDate } from "@/utils/date.js";

const ADD = "新增";
const MODIFY = "修改";
const DELETE = "删除";
const INFO = "详情";
const SPELL = "拼穴";

export default {
  name: "ashesManage",
  props: {
    orderType: {
      type: String,
      default() {
        return ADD;
      }
    }
  },
  data() {
    return {
      title: null,
      ashesData: {},

      xMax: 100,
      yMax: 100,

      usetype: [],
      xblx: [],
      TMXSTATUSS: [],

      TMXSTATUSA: null,

      ashesTypes: [],
      areaTypes: []
    };
  },
  watch: {
    "ashesData.ASSASAID": function(val) {
      if (
        this.ashesData.ASSASAID !== null &&
        this.ashesData.ASSASAID !== undefined &&
        this.ashesData.ASSASAID !== ""
      ) {
        var data = {
          ASAID: this.ashesData.ASSASAID
        };
        apiBase.DoService(
          data,
          apiBase.getApiAdress().Ashesarea.Detail,
          res => {
            this.xMax = res.data.content.ASAXCOUNT;
            this.yMax = res.data.content.ASAYCOUNT;
          },
          res => {
            this.$message.error(res.data.msg);
          }
        );
      }
    }
  },
  methods: {
    getCode() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Registration.QueryAllCode,
        res => {
          this.codeList = res.data.content;
          for (var i in this.codeList) {
            switch (this.codeList[i].CTPID) {
              case "性别类型":
                this.xblx = this.codeList[i].Cods;
                break;
              default:
            }
          }
        }
      );
    },
    //获取所属墓型
    getCemeteryData() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Code.GetTombtype,
        res => {
          this.usetype = res.data.content;
        }
      );
    },
    //获取销售状态
    gettmxstatus() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Tombsdata.GetTMXSTATUS,
        res => {
          this.TMXSTATUSS = res.data.content;
        }
      );
    },
    //功能操作
    open(order,id) {
      this.order = order;
      this.dataRepeat();
      switch (this.order) {
        case ADD:
          this.title = "墓穴新增";
          this.initSelectData();//初始化下拉框数据
          this.$refs.dialog.open();
          break;
        case SPELL:
          this.title = "拼穴";
          this.ashesData.TMMPOSTION = id
          this.initSelectData();//初始化下拉框数据
          this.$refs.dialog.open();
          break;
        case MODIFY:
          this.title = "墓穴修改";
          this.dataInfo(id);
          this.initSelectData();//初始化下拉框数据
          this.$refs.dialog.open();
          break;
        case DELETE:
          this.dataDelete(id);
          break;
        case INFO:
          this.title = "墓穴详情";
          this.dataInfo(id);
          this.$refs.dialogInfo.open();
          break;
        default:
      }
    },
    //提交
    submit() {
      switch (this.order) {
        case ADD:
          this.dataAdd();
          break;
        case SPELL:
          this.dataAdd();
          break;
        case MODIFY:
          this.dataModify();
          break;
        case DELETE:
          break;
        case INFO:
          this.$refs.dialogInfo.close();
          break;
        default:
      }
    },
    //取消
    cancel() {
      this.$refs.dialog.close();
      this.$refs.dialogInfo.close();
    },
    //墓穴新增
    dataAdd() {
      let data = JSON.parse(JSON.stringify(this.ashesData));
      if(this.ashesData.TMMDEATHDATE){
        data.TMMDEATHDATE =  formatDate(this.ashesData.TMMDEATHDATE, "yyyyMMdd");
      }
      if(this.ashesData.TMMBURIALDATE){
        data.TMMBURIALDATE =  formatDate(this.ashesData.TMMBURIALDATE, "yyyyMMdd");
      }
      if(this.ashesData.TMMMOVEOUTDATE){
        data.TMMMOVEOUTDATE =  formatDate(this.ashesData.TMMMOVEOUTDATE, "yyyyMMdd");
      }
      if(this.ashesData.TMMPURCHASEDATE){
        data.TMMPURCHASEDATE =  formatDate(this.ashesData.TMMPURCHASEDATE, "yyyyMMdd");
      }
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Tombs.Create,
        res => {
          this.refreshData();
          this.$refs.dialog.close();
          this.$message({
            message: this.order + res.data.msg,
            type: "success"
          });
        },
        res => {
          this.$message.error(res.data.msg);
        }
      );
    },
    //墓穴修改
    dataModify() {
      let data = JSON.parse(JSON.stringify(this.ashesData));
      if(this.ashesData.TMMDEATHDATE){
        data.TMMDEATHDATE =  formatDate(this.ashesData.TMMDEATHDATE, "yyyyMMdd");
      }
      if(this.ashesData.TMMBURIALDATE){
        data.TMMBURIALDATE =  formatDate(this.ashesData.TMMBURIALDATE, "yyyyMMdd");
      }
      if(this.ashesData.TMMMOVEOUTDATE){
        data.TMMMOVEOUTDATE =  formatDate(this.ashesData.TMMMOVEOUTDATE, "yyyyMMdd");
      }
      if(this.ashesData.TMMPURCHASEDATE){
        data.TMMPURCHASEDATE =  formatDate(this.ashesData.TMMPURCHASEDATE, "yyyyMMdd");
      }
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Tombs.Modify,
        res => {
          this.refreshData();
          this.$refs.dialog.close();
          this.$message({
            message: this.order + res.data.msg,
            type: "success"
          });
        },
        res => {
          this.$message.error(res.data.msg);
        }
      );
    },
    //墓穴删除
    dataDelete(id) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(callback => {
        var data = {
          TMMID: id
        };
        apiBase.DoService(
          data,
          apiBase.getApiAdress().Tombs.Delete,
          res => {
            this.refreshData();
            this.$message({
              message: this.order + res.data.msg,
              type: "success"
            });
          },
          res => {
            this.$message.error(res.data.msg);
          }
        );
      });
    },
    //位置详情
    dataInfo(id) {
      var data = {
        TMMID: id
      };
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Tombs.Detail,
        res => {
          this.ashesData = res.data.content;
          this.ashesData.TMMID = id;
          this.TMXSTATUSA = this.tmxstatusa(this.ashesData.TMXSTATUS);
        },
        res => {
          this.$message.error(res.data.msg);
        }
      );
    },
    tmxstatusa(val){
        switch(val){
          case "A":
            return "可售";
          break;
          case "B":
            return "预售";
          break;
          case "C":
            return "已售";
          break;
          case "D":
            return "已使用";
          break;
          case "E":
            return "已迁出";
          break;
          case "F":
            return "禁售";
          break;
          default:
        }
    },
    //数据重置
    dataRepeat() {
      this.ashesData = {};
    },
    //初始化下拉框数据
    initSelectData() {
      this.getCemeteryData();
      this.gettmxstatus();
      this.getCode();
    },
    refreshData() {
      this.$emit("refreshData");
    },
    closeDialog() {
      if (this.order === ADD || this.order === MODIFY)
        this.$refs.dialog.close();
      else if (this.order === INFO) this.$refs.dialogInfo.close();
    }
  },
  components: {
    sweetModal
  },
  mounted() {},
  created() {}
};
</script>